use super::*;

#[test]
fn test_jump() {
    assert_eq!(Jump::bin(None).unwrap_or_default(), 0b0);
    assert!(Jump::bin(Some("JJJ")).is_err());
    assert_eq!(Jump::bin(Some("JGT")).unwrap_or_default(), 0b1);
    assert_eq!(Jump::bin(Some("JEQ")).unwrap_or_default(), 0b10);
    assert_eq!(Jump::bin(Some("JGE")).unwrap_or_default(), 0b11);
    assert_eq!(Jump::bin(Some("JLT")).unwrap_or_default(), 0b100);
    assert_eq!(Jump::bin(Some("JNE")).unwrap_or_default(), 0b101);
    assert_eq!(Jump::bin(Some("JLE")).unwrap_or_default(), 0b110);
    assert_eq!(Jump::bin(Some("JMP")).unwrap_or_default(), 0b111);
}

#[test]
fn test_dest() {
    assert_eq!(Dest::bin(None).unwrap_or_default(), 0b0);
    assert!(Dest::bin(Some("JJJ")).is_err());
    assert_eq!(Dest::bin(Some("M")).unwrap_or_default(), 0b1);
    assert_eq!(Dest::bin(Some("D")).unwrap_or_default(), 0b10);
    assert_eq!(Dest::bin(Some("DM")).unwrap_or_default(), 0b11);
    assert_eq!(Dest::bin(Some("A")).unwrap_or_default(), 0b100);
    assert_eq!(Dest::bin(Some("AM")).unwrap_or_default(), 0b101);
    assert_eq!(Dest::bin(Some("AD")).unwrap_or_default(), 0b110);
    assert_eq!(Dest::bin(Some("ADM")).unwrap_or_default(), 0b111);
}

#[test]
fn test_comp() {
    assert!(Comp::bin("01").is_err());
    assert_eq!(Comp::bin("0").unwrap_or_default(), 0b101010);
    assert_eq!(Comp::bin("1").unwrap_or_default(), 0b111111);
    assert_eq!(Comp::bin("-1").unwrap_or_default(), 0b111010);
    assert_eq!(Comp::bin("A").unwrap_or_default(), 0b110000);
    assert_eq!(Comp::bin("M").unwrap_or_default(), 0b1110000);
    assert_eq!(Comp::bin("!D").unwrap_or_default(), 0b001101);
    assert_eq!(Comp::bin("!A").unwrap_or_default(), 0b110001);
    assert_eq!(Comp::bin("!M").unwrap_or_default(), 0b1110001);
    assert_eq!(Comp::bin("-D").unwrap_or_default(), 0b001111);
    assert_eq!(Comp::bin("-A").unwrap_or_default(), 0b110011);
    assert_eq!(Comp::bin("-M").unwrap_or_default(), 0b1110011);
    assert_eq!(Comp::bin("D+1").unwrap_or_default(), 0b011111);
    assert_eq!(Comp::bin("A+1").unwrap_or_default(), 0b110111);
    assert_eq!(Comp::bin("M+1").unwrap_or_default(), 0b1110111);
    assert_eq!(Comp::bin("D-1").unwrap_or_default(), 0b001110);
    assert_eq!(Comp::bin("A-1").unwrap_or_default(), 0b110010);
    assert_eq!(Comp::bin("M-1").unwrap_or_default(), 0b1110010);
    assert_eq!(Comp::bin("D+A").unwrap_or_default(), 0b000010);
    assert_eq!(Comp::bin("D+M").unwrap_or_default(), 0b1000010);
    assert_eq!(Comp::bin("D-A").unwrap_or_default(), 0b010011);
    assert_eq!(Comp::bin("D-M").unwrap_or_default(), 0b1010011);
    assert_eq!(Comp::bin("A-D").unwrap_or_default(), 0b000111);
    assert_eq!(Comp::bin("M-D").unwrap_or_default(), 0b1000111);
    assert_eq!(Comp::bin("D&A").unwrap_or_default(), 0b000000);
    assert_eq!(Comp::bin("D&M").unwrap_or_default(), 0b1000000);
    assert_eq!(Comp::bin("D|A").unwrap_or_default(), 0b010101);
    assert_eq!(Comp::bin("D|M").unwrap_or_default(), 0b1010101);
}
